using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Hermes.Framework.Implementation.File
{
    public class TxFileDelete : 
        TxOperationTemplate, ITransactableDelete
    {
        public TxFileDelete(string fileName)
            : base(fileName)
        {
            
        }

        public void Delete()
        {
            base.Execute(dstFileName);
        }

        protected override void Operate()
        {
            if (!this.fileSystem.Exists(this.dstFileName))
            {
                throw new FileNotFoundException(this.dstFileName);
            }
            this.fileSystem.Rename(this.dstFileName, this.shadowFileName);
        }

        public override void Commit()
        {
            this.fileSystem.Delete(this.shadowFileName);
        }

        public override void Rollback()
        {
            Console.WriteLine("Rollback Delete File");
            this.fileSystem.Rename(this.shadowFileName, this.dstFileName);
        }
    }
}
